package com.lhy.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhy.domain.Classify;
import com.lhy.goods.service.ClassifyService;
import com.lhy.goods.mapper.ClassifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author lhy
* @description 针对表【goods_classify(分类表)】的数据库操作Service实现
* @createDate 2024-07-27 10:29:52
*/
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify>
    implements ClassifyService{
    @Autowired
    private ClassifyMapper classifyMapper;

    @Override
    public Integer insertClassify(Classify classify) {
        return classifyMapper.insert(classify);
    }

    @Override
    public Integer updateClassify(Classify classify) {
        return classifyMapper.updateById(classify);
    }

    @Override
    @Transactional
    public Integer deleteClassify(String ids) {
        String[] split = ids.split(",");
        try {
            for (String id : split) {
                Classify classify =new Classify();
                classify.setId(Long.parseLong(id));
                classify.setIsDelete(1);
                classifyMapper.updateById(classify);
            }
            return 1;
        } catch (NumberFormatException e) {
            return -1;
        }
    }

    @Override
    public List<Classify> selectAll() {
        LambdaQueryWrapper<Classify> classifyLambdaQueryWrapper = new LambdaQueryWrapper<>();
        classifyLambdaQueryWrapper.eq(Classify::getIsDelete ,0);
        return classifyMapper.selectList(classifyLambdaQueryWrapper);
    }
}




